package com.linkoog.devtools.toolwindow_manager;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 */
public abstract class AbstractApplyAvailabilitiesAction extends AnAction {
    @NotNull
    protected abstract List<ToolWindowPreference>
    getPreferencesToApply(@NotNull final ToolWindowManagerProjectComponent toolWindowManagerProjectComponent);

    @Override
    public void actionPerformed(AnActionEvent e) {
        final Project project = e.getDataContext().getData(CommonDataKeys.PROJECT);

        if (project != null && !project.isDefault()) {
            final ToolWindowManagerProjectComponent component = project.getComponent(ToolWindowManagerProjectComponent.class);
            final List<ToolWindowPreference> toolWindowPreferences = getPreferencesToApply(component);
            final ToolWindowPreferenceApplier toolWindowPreferenceApplier = new ToolWindowPreferenceApplier(project);

            toolWindowPreferenceApplier.applyPreferencesFrom(toolWindowPreferences);
        }
    }
}
